import { useSelector } from 'react-redux'
import { StateType } from '../store'
import { ComponentsStateType } from '../store/componentsReducer'
function useGetComponentsInfo() {
  const components = useSelector<StateType>(
    state => state.components.present
  ) as ComponentsStateType

  const { componentList = [], selectedId, copiedComponent } = components

  const selectedComponent = componentList.find(c => c.fe_id === selectedId)
  // 这里selectedComponent的值可能是组件 也可能是undefined 因为find如果没有找到则返回undefined
  return { componentList, selectedId, selectedComponent, copiedComponent }
}

export default useGetComponentsInfo
